<?php

include "header.php";
$page = "delete_transaction";

//check user login
if (!$user->user_exists) {
    header('Location: ./login.php');
    exit();
}
if ($user->user_info['type_id'] != 1) {
    header('Location: ./restrict.php');
    exit();
}
$transaction = array();
$class = new Transaction();

if (isset($_POST['id'])) {
    $id = $_POST['id'];
} elseif (isset($_GET['id'])) {
    $id = $_GET['id'];
}

if (!empty($id)) {
    $transaction = $class->getTransactions($id);
}
if (empty($transaction)) {
    header('Location: ./restrict.php');
    exit();
}

$class->deleteTransaction($id);
header('Location: ./transactions.php');
exit();
